package com.ruoyi.web.controller.system;

import java.util.List;
import java.util.Arrays;
import java.util.concurrent.TimeUnit;

import com.ruoyi.common.xss.Xss;
import lombok.RequiredArgsConstructor;
import javax.servlet.http.HttpServletResponse;
import javax.validation.constraints.*;
import cn.dev33.satoken.annotation.SaCheckPermission;
import org.springframework.web.bind.annotation.*;
import org.springframework.validation.annotation.Validated;
import com.ruoyi.common.annotation.RepeatSubmit;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.PageQuery;
import com.ruoyi.common.core.domain.R;
import com.ruoyi.common.core.validate.AddGroup;
import com.ruoyi.common.core.validate.EditGroup;
import com.ruoyi.common.core.validate.QueryGroup;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.system.domain.vo.AppMessageNoticeVo;
import com.ruoyi.system.domain.bo.AppMessageNoticeBo;
import com.ruoyi.system.service.IAppMessageNoticeService;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 消息通知
 *
 * @author ruoyi
 * @date 2025-09-29
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/system/messageNotice")
public class AppMessageNoticeController extends BaseController {

    private final IAppMessageNoticeService iAppMessageNoticeService;

    /**
     * 查询消息通知列表
     */
    @SaCheckPermission("system:messageNotice:list")
    @GetMapping("/list")
    public TableDataInfo<AppMessageNoticeVo> list(AppMessageNoticeBo bo, PageQuery pageQuery) {
        return iAppMessageNoticeService.queryPageList(bo, pageQuery);
    }

    /**
     * 导出消息通知列表
     */
    @SaCheckPermission("system:messageNotice:export")
    @Log(title = "消息通知", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(AppMessageNoticeBo bo, HttpServletResponse response) {
        List<AppMessageNoticeVo> list = iAppMessageNoticeService.queryList(bo);
        ExcelUtil.exportExcel(list, "消息通知", AppMessageNoticeVo.class, response);
    }

    /**
     * 获取消息通知详细信息
     *
     * @param id 主键
     */
    @SaCheckPermission("system:messageNotice:query")
    @GetMapping("/{id}")
    public R<AppMessageNoticeVo> getInfo(@NotNull(message = "主键不能为空")
                                     @PathVariable String id) {
        return R.ok(iAppMessageNoticeService.queryById(id));
    }

    /**
     * 新增消息通知
     */
    @SaCheckPermission("system:messageNotice:add")
    @Log(title = "消息通知", businessType = BusinessType.INSERT)
    @RepeatSubmit()
    @PostMapping()
    public R<Void> add(@Validated(AddGroup.class) @RequestBody AppMessageNoticeBo bo) {
        return toAjax(iAppMessageNoticeService.insertByBo(bo) ? 1 : 0);
    }

    /**https://lanhuapp.com/link/#/invite?sid=lX00QblA
     * 修改消息通知
     */
    @SaCheckPermission("system:messageNotice:edit")
    @Log(title = "消息通知", businessType = BusinessType.UPDATE)
    @RepeatSubmit()
    @PutMapping()
    public R<Void> edit(@Validated(EditGroup.class) @RequestBody AppMessageNoticeBo bo) {
        return toAjax(iAppMessageNoticeService.updateByBo(bo) ? 1 : 0);
    }

    /**
     * 删除消息通知
     *
     * @param ids 主键串
     */
    @SaCheckPermission("system:messageNotice:remove")
    @Log(title = "消息通知", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public R<Void> remove(@NotEmpty(message = "主键不能为 空")
                          @PathVariable String[] ids) {
        return toAjax(iAppMessageNoticeService.deleteWithValidByIds(Arrays.asList(ids), true) ? 1 : 0);
    }
}
